
import org.apache.spark.sql.SparkSession


object UnionRDD {
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("UnionRDDExample")
      .master("local[*]")
      .getOrCreate()


    val sc = spark.sparkContext


    val rdd1 = sc.parallelize(Seq(("a", 1), ("b", 2), ("c", 3)))
    val rdd2 = sc.parallelize(Seq(("a", 1), ("d", 4), ("e", 5)))


    val unionRDD = rdd1.union(rdd2)


    println("合并后的 RDD 内容：")
    unionRDD.collect().foreach(println)

  }
}
